package com.norns.torque.dialog

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.gyf.immersionbar.ImmersionBar
import com.hi.dhl.binding.viewbind
import com.norns.torque.databinding.DialogCancelConfirmBinding

class AppCommonDialog :CommonDialog(){
    companion object{
        fun newInstance(content:String):AppCommonDialog {
            val args = Bundle()
            args.putString("content",content)
            val fragment = AppCommonDialog()
            fragment.arguments = args
            return fragment
        }
    }
    private val binding by viewbind<DialogCancelConfirmBinding>()
    private var btnClickListener:((isConfirm:Boolean)->Unit)?=null

    fun setClickListener(listener:(isConfirm:Boolean)->Unit){
        btnClickListener=listener
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        screenWidthAspect=0.9f
        return binding.root
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val content=arguments?.getString("content")?:""
        binding.tvMsg.text=content
        binding.btnConfirm.setOnClickListener {
            btnClickListener?.invoke(true)
            dismiss()
        }
        binding.btnCancel.setOnClickListener {
            btnClickListener?.invoke(false)
            dismiss()
        }
    }


}